#ifndef HSE_DOCUMENT_META_DATAS_H
#define HSE_DOCUMENT_META_DATAS_H

#include <stdio.h>
#include <string>
#include <hash_map>
#include "hse_common.h"
#include "hse_types.h"
#include "document_meta_datas.h"

namespace hse {


using std::string;
using stdext::hash_map;

class DocumentMetaDatas {
public:
	inline static DocumentMetaDatas& Instance() {
		if (instance_ == NULL) {
			instance_ = new DocumentMetaDatas();
		}
		return *instance_;
	}
	inline static void Destroy() { 
		if (instance_ != NULL)
			delete instance_; 
	}
	string GetContent(int doc_id, int start_pos, int length);
	DocumentMetaData* GetMetaData(int doc_id);
	void AddMetaData(DocumentMetaData& meta);
	void Dump(FILE *f);
	void Load(FILE *f);
	inline size_t GetTotalDocument() { return total_document_; }
	~DocumentMetaDatas();
private:
	hash_map<int, DocumentMetaData*> metas_; 
	static DocumentMetaDatas *instance_;
	double avdl_;
	long long total_dl_;
	size_t total_document_;

	DocumentMetaDatas()
		:avdl_(0), total_dl_(0), total_document_(0)
	{} //private constructor
	DISALLOW_COPY_AND_ASSIGN(DocumentMetaDatas);
};

} //end of namespace

#endif